package com.xinhua.erp.controller;

import com.xinhua.erp.pojo.Result;
import com.xinhua.erp.pojo.Retail;
import com.xinhua.erp.service.RetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("retail")
public class RetailController {
    @Autowired
    private RetailService retailService;


    @GetMapping("{id}")
    public Result findById(@PathVariable long id) {
        return retailService.findById(id);
    }

    @GetMapping("{type}/{page}/{size}")
    public Result findAll(@PathVariable String type,@PathVariable int page, @PathVariable int size) {
        return retailService.findAll(type,page, size);
    }

    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable long id) {
        return retailService.deleteById(id);
    }

    @PostMapping
    public Result save(@RequestBody Retail retail) {
        return retailService.save(retail);
    }

    @PutMapping("{id}")
    public Result update(@PathVariable Long id,@RequestBody Retail retail) {
        return retailService.update(id,retail);
    }
    @PostMapping("search/{page}/{size}")
    public Result Search(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size){
        return retailService.Search(searchMap,page,size);
    }
    @PutMapping("status/{id}")
    public Result updateStatus(@PathVariable Long id){
        return retailService.updateStatus(id);
    }
}